<?php

namespace app\common\model\mall;

use think\Model;

class Raty extends Model
{

    // 追加属性
    protected $append = [
        "totalraty5",
        "goodsraty5",
        "serviceraty5",
        "timeraty5",
    ];

    public function getTotalraty5Attr($value, $data){
        return self::raty5($data['totalraty'],$data['users'],3);
    }

    public function getGoodsraty5Attr($value, $data){
        return self::raty5($data['goodsraty'],$data['users']);
    }

    public function getServiceraty5Attr($value, $data){
        return self::raty5($data['serviceraty'],$data['users']);
    }

    public function getTimeraty5Attr($value, $data){
        return self::raty5($data['timeraty'],$data['users']);
    }

    /**
     * 积分转换为五分制
     * @param int $score 积分汇总数
     * @param int $users 汇总用户数
     * @param int $total 汇总项数
     * @return int
     */
    public static function raty5($score,$users,$total = 1){
        if((int)$score==0 || $users==0) return 0;
        return round($score/$total/$users,0);
    }

}
